package service

import (
	"fmt"
	"gin_session/internal/domain/model"
)

type SysUserService struct {
}

func NewSysUserService() *SysUserService {
	return &SysUserService{}
}

func (this *SysUserService) Login(
	userName string,
	passWord string) (bool, error) {

	//校验 userName 与 passWrod 不能为空!
	if userName == "" || passWord == "" {
		return false, fmt.Errorf("参数不能为空!")
	}

	// 校验登录用户密码是否正确
	var checkFlag bool = false

	// 查找 userName
	for _, v := range model.UserList() {
		if userName == v.UserName && passWord == v.PassWord {
			checkFlag = true //正确
			break
		}
	}

	if !checkFlag {
		return false, fmt.Errorf("用户名或密码错误!")
	}

	return checkFlag, nil
}
